package com.angis.fx.activity.service;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;

import com.angis.fx.data.ContextInfo;
import com.angis.fx.handler.login.OnlineLoginHandler;

public class OnlineLoginService extends Service {
	
	private Intent mIntent;
	
	@Override
	public void onCreate() {
		super.onCreate();
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		mIntent = new Intent("loginaction");
		try {
			String lUsername = intent.getExtras().getString("username");
			String lPwd = intent.getExtras().getString("pwd");
			String lDeviceid = intent.getExtras().getString("deviceid");
			ContextInfo lContextInfo = OnlineLoginHandler.login(this, lUsername, lPwd, lDeviceid);
			Bundle lBundle = new Bundle();
			lBundle.putSerializable("results", lContextInfo);
			mIntent.putExtras(lBundle);
			this.sendBroadcast(mIntent);
		} catch (Exception e) {
			this.sendBroadcast(mIntent);
		} finally {this.stopSelf();}
	}

}
